/**
 * 
 */
package operation;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Sevelet for deployment.
 * 
 * @author chuxiaoyuan
 *
 */
public class DeploymentServlet extends HttpServlet {

	private static final long serialVersionUID = -3469161932810052803L;

	/**
	 * Constructor.
	 */
	public DeploymentServlet() {
		// 
	}

	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		PrintWriter out = response.getWriter();
		
		try {
			if (Deploy.TURN_ON) {
				// Run deployments.
				Deploy.execute();
			}
			
		} catch (Exception e) {

			e.printStackTrace();
			e.printStackTrace(out);
			return;
		}
		
		out.println("<h1>Deployment Complete.</h1><hr/>");
	}

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}
